package sk.naive.talker.command;

import sk.naive.talker.*;
import sk.naive.talker.props.*;
import sk.naive.talker.message.DefaultMessageFactory;

import java.rmi.RemoteException;
import java.util.*;

/**
 * AddressedPublicMessageCommand.
 *
 * @author <a href="mailto:virgo@naive.deepblue.sk">Richard "Virgo" Richter</a>
 * @version $Revision: 1.19 $ $Date: 2005/03/15 19:59:28 $
 */
public abstract class AddressedPublicMessageCommand extends AddressedMessageCommand {
	protected void execSend(User recipient, String message) throws CommandException, RemoteException, PropertyStoreException {
		sendAddressedPublicMessage(user, recipient, message);
		if (recipient.get(User.UPROP_HIGHLIGHT_ADDRESSED_MESSAGE).equals(HighlightColourProperty.HLC_MY_COLOUR)) {
			sendRecipientMessage(recipient, getRecipientHighlighted2MessageKey(message));
		} else if (!recipient.get(User.UPROP_HIGHLIGHT_ADDRESSED_MESSAGE).equals(HighlightColourProperty.HLC_NONE)) {
			sendRecipientMessage(recipient, getRecipientHighlightedMessageKey(message));
		} else {
			sendRecipientMessage(recipient, getRecipientMessageKey(message));
		}
	}

	private void sendAddressedPublicMessage(User sender, User recipient, String s) throws RemoteException, CommandException {
		Collection excluded = new HashSet();
		sender.getProperties().put(DefaultMessageFactory.CTXKEY_VAL + "Rcp", recipient.getProperties());
		excluded.add(recipient);
		sendPublicMessage(sender, s, excluded);
	}

	public String getRecipientHighlightedMessageKey(String message) {
		return getRecipientMessageKey(message);
	}

	public String getRecipientHighlighted2MessageKey(String message) {
		return getRecipientMessageKey(message);
	}

	public String getStoredMessageKey(String message) {
		return getAudienceMessageKey(message);
	}

	protected boolean isSecureTargetSearch() {
		return false;
	}
}
